package com.zhoug.common.utils;

import android.content.res.ColorStateList;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;

import androidx.core.graphics.drawable.DrawableCompat;

/**
 * Drawable 工具
 *
 * @Author 35574
 * @Date 2020/9/4
 * @Description
 */
public class DrawableUtils {

    /**
     * 设置drawable的大小
     *
     * @param drawable
     * @param width
     * @param height
     */
    public static void setDrawableSize(Drawable drawable, int width, int height) {
        if (drawable != null && (width>0 || height>0)) {
            Rect oldBounds = drawable.getBounds();
            int left = oldBounds.left;
            int top = oldBounds.top;
            int right = oldBounds.right;
            int bottom = oldBounds.bottom;
            if (width > 0) {
                right = left + width;
            }
            if (height > 0) {
                bottom = top + height;
            }
            drawable.setBounds(left, top, right, bottom);
        }
    }


}

